package com.example.applicationview;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.example.applicationview.drawable.MaskFilterDrawable;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 1, 将图片分割，再拼接到一块
 *
 */
public class MyViewGroupActivity extends AppCompatActivity {

    @BindView(R.id.view_test)
    LinearLayout viewTest;
    @BindView(R.id.image_1)
    ImageView image1;
    @BindView(R.id.image_2)
    ImageView image2;
    @BindView(R.id.image_3)
    ImageView image3;
    @BindView(R.id.image_4)
    ImageView image4;
    @BindView(R.id.image_0)
    ImageView image0;
    @BindView(R.id.image_01)
    ImageView image01;
    @BindView(R.id.image_02)
    ImageView image02;
    @BindView(R.id.image_03)
    ImageView image03;
    @BindView(R.id.image_04)
    ImageView image04;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_group);
        ButterKnife.bind(this);

        //将图片分割，再拼接到一块
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.image_0);
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, width / 2, height / 2);
        Bitmap bitmap2 = Bitmap.createBitmap(bitmap, width / 2, 0, width / 2, height / 2);
        Bitmap bitmap3 = Bitmap.createBitmap(bitmap, 0, height / 2, width / 2, height / 2);
        Bitmap bitmap4 = Bitmap.createBitmap(bitmap, width / 2, height / 2, width / 2, height / 2);
        image1.setImageBitmap(bitmap1);
        image2.setImageBitmap(bitmap2);
        image3.setImageBitmap(bitmap3);
        image4.setImageBitmap(bitmap4);

        image01.setImageBitmap(bitmap1);
        image02.setImageBitmap(bitmap2);
        image03.setImageBitmap(bitmap3);
        image04.setImageBitmap(bitmap4);
        //设置发光背景
        viewTest.setBackground(new MaskFilterDrawable(getResources().getColor(R.color.active)));

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        //获取 当前时间是 本年度的第几周
        Calendar calendar = Calendar.getInstance();
//        Integer weekNo = (Integer) calendar.get(Calendar.WEEK_OF_YEAR);
//        String weekNoOfYear = getWeekNoOfYear(calendar);
//        Log.e("weekNo" , weekNo + " " + weekNoOfYear);


        //当前时间的 本周第一天
//        Date weekStartDate = getWeekStartDate(calendar);
//        String time = format.format(weekStartDate);
//        Log.e("weekNo" , "" + time);

        String str1 = "2021-01-02 12-12-12";
        try {
            Date parse = format.parse(str1);
            calendar.setTime(parse);
            Integer weekNo2 = (Integer) calendar.get(Calendar.WEEK_OF_YEAR);
            String weekNoOfYear2 = getWeekNoOfYear(calendar);
            Log.e("weekNo", weekNo2 + " " + weekNoOfYear2);

            Date weekStartDate2 = getWeekStartDate(calendar);
            String time2 = format.format(weekStartDate2);
            Log.e("weekNo", "" + time2);


        } catch (ParseException e) {
            e.printStackTrace();
        }


    }

    //获取本周 第一天
    public static Date getWeekStartDate(Calendar cal) {
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        Date date = cal.getTime();
        return date;
    }

    //获取本年 第几周
    public static String getWeekNoOfYear(Calendar calendar) {
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
//        calendar.setMinimalDaysInFirstWeek(4);
        int year = calendar.get(Calendar.YEAR);
        Integer weekNo = (Integer) calendar.get(Calendar.WEEK_OF_YEAR);
        String weekNoStr = weekNo.toString();
        if (weekNo < 10) {
            weekNoStr = "0" + weekNoStr;
        }
        return year + "-" + weekNoStr;
    }


}
